package com.neusoft.yuejian_01.model;

import com.neusoft.yuejian_01.base.BaseModel;
import com.neusoft.yuejian_01.javabean.ActivityBean;
import com.neusoft.yuejian_01.javabean.ActivityRegBean;
import com.neusoft.yuejian_01.javabean.IsActivityReg;
import com.neusoft.yuejian_01.javabean.NoRegBean;
import com.neusoft.yuejian_01.listener.RetrofitListener;
import com.neusoft.yuejian_01.service.ActivityService;

import java.util.List;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

/**
 * Created by Administrator on 2017/9/28.
 */

public class ActivityModel extends BaseModel {
    //活动列表
    public void activitylist(final RetrofitListener listener) {
        this.flag = Const.ActiivityList;
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call<List<ActivityBean>> call = activityService.getActivitylist();
        Callback<List<ActivityBean>> callback = new Callback<List<ActivityBean>>() {
            @Override
            public void onResponse(Call<List<ActivityBean>> call, Response<List<ActivityBean>> response) {
                List<ActivityBean> activityBean = response.body();
                listener.onSuccess(activityBean,flag);
            }
            @Override
            public void onFailure(Call<List<ActivityBean>> call, Throwable t) {
                listener.onFail();
            }
        };
        call.enqueue(callback);
    }
    //活动详情
    public void activityDetail(String a_id,final RetrofitListener listener) {
        this.flag = Const.ActivityDetail;
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call call = activityService.getActivityDetail(a_id);
        call.enqueue(new Callback<ActivityBean>() {
            @Override
            public void onResponse(Call<ActivityBean> call, Response<ActivityBean> response) {
                ActivityBean activityBean=response.body();
                listener.onSuccess(activityBean,flag);
            }
            @Override
            public void onFailure(Call<ActivityBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //判断报名
    public void getIsReg(String u_id, String a_id,final RetrofitListener listener) {
        this.flag = Const.IsActivityReg;
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call call = activityService.getIsReg(u_id,a_id);
        call.enqueue(new Callback<IsActivityReg>() {
            @Override
            public void onResponse(Call<IsActivityReg> call, Response<IsActivityReg> response) {
                IsActivityReg isActivityReg=response.body();
                listener.onSuccess(isActivityReg,flag);
            }
            @Override
            public void onFailure(Call<IsActivityReg> call, Throwable t) {
                listener.onFail();
            }
        });

    }
    //取消报名
    public void getIsNotReg(String u_id, String a_id,final RetrofitListener listener) {
        this.flag = Const.NoReg;
        ActivityService activityService = retrofit.create(ActivityService.class);;
        Call call = activityService.getIsNotReg(u_id,a_id);
        call.enqueue(new Callback<NoRegBean>() {
            @Override
            public void onResponse(Call<NoRegBean> call, Response<NoRegBean> response) {
                NoRegBean noRegBean=response.body();
                listener.onSuccess(noRegBean,flag);
            }
            @Override
            public void onFailure(Call<NoRegBean> call, Throwable t) {
                listener.onFail();
            }
        });
    }
    //报名订单信息
    public void getActivityRegistration(String u_id,String a_id,final RetrofitListener listener){
        this.flag = Const.ActivityOrder;
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call call = activityService.getActivityRegistration(u_id,a_id);
        call.enqueue(new Callback<ActivityRegBean>() {
            @Override
            public void onResponse(Call<ActivityRegBean> call, Response<ActivityRegBean> response) {
                ActivityRegBean activityRegBean=response.body();
                listener.onSuccess(activityRegBean,flag);
            }
            @Override
            public void onFailure(Call<ActivityRegBean> call, Throwable t)  {
                listener.onFail();
            }
        });
    }
    //活动报名
    public void activityreg(String u_id,String a_id,final RetrofitListener listener){
        this.flag = Const.ActivityReg;
        ActivityService activityService = retrofit.create(ActivityService.class);
        Call call = activityService.addActivityRegistration(u_id,a_id);
        call.enqueue(new Callback<ActivityRegBean>() {
            @Override
            public void onResponse(Call<ActivityRegBean> call, Response<ActivityRegBean> response) {
                ActivityRegBean activityRegBean=response.body();
                listener.onSuccess(activityRegBean,flag);
            }
            @Override
            public void onFailure(Call<ActivityRegBean> call, Throwable t)  {
                listener.onFail();
            }
        });
    }
}







